<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<table id="leave_table">
    <thead>
    <th data-options="field:'id'">ID</th>
    <th data-options="field:'date',formatter:dateFormater">请假时间</th>
    <th data-options="field:'advise'">审批意见</th>
    <th data-options="field:'status',formatter:statusFormatter">状态</th>
    </thead>
</table>
<div id="leave_tool">
    <a href="#" class="easy-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="doLeaveAdd()">添加</a>
    <a href="#" class="easy-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="doLeaveUpdate()">重提</a>
</div>
<div id="leave_dialog" class="easyui-dialog" title="编辑请假条"
     data-options="modal:true,closed:true,href:'<%=request.getContextPath()%>/system/leave.html?act=go_edit',footer:'#leave_buttons'"
     style="width: 480px;height: 300px">
    s
</div>
<div id="leave_buttons" style="padding: 5px 15px 5px 0px;text-align: right">
    <a href="#" class="easy-linkbutton" data-options="iconCls:'icon-ok'" onclick="submitLeaveForm()">提交</a>
    <a href="#" class="easy-linkbutton" onclick="doCancel('leave_dialog')">取消</a>
</div>

<script type="text/javascript">
    function dateFormater(value,row,index) {
        return row.startDate+"-"+row.endDate;
    }
    function statusFormatter(value,row,index) {
        switch (value){
            case -2:return "拒绝"
            case -1:return "驳回"
            case 0:return "待审核"
            case 1:return "同意"
        }
    }
    $(function () {
        $("#leave_table").datagrid({
            url:"/system/leave.html?act=list",
            singleSelect:true,
            toolbar:"#leave_tool"
        })
    })

    function myFormatter(s) {
        var y=s.getFullYear();
        var m=s.getMonth()+1;
        var d=s.getDate();
        debugger
        return y+"-"+(m<10?("0"+m):m)+"-"+(d<10?("0"+d):d);

    }

    function myParse(s) {
        if(!s) return new Date();
        var ss = s.split("-");
        var y = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var d = parseInt(ss[2],10);
        debugger
        if(!isNaN(y)&&!isNaN(m)&&!isNaN(d)){
            return new Date(y,m-1,d);
        }else{
            return new Date();
        }
    }

    function doLeaveAdd() {
        $("#leave_dialog").dialog("open");
    }
    function doLeaveUpdate() {
        var row = $("#leave_table").datagrid("getSelected");
        if (row == null || row.length == 0){
            return;
        }
        $("#leave_dialog").dialog({
            onLoad:function () {
                $("#leave_form").form("load",{
                    id:row.id,
                    startDate:row.startDate,
                    endDate:row.endDate,
                    reason:row.reason
                })
            }
        }).dialog("open");
    }

    function doCancel(domId) {
        $("#"+domId).dialog("close")
    }

    function submitLeaveForm() {
        $.ajax({
            url:"<%=request.getContextPath()%>/system/leave.html?act=edit",
            data:$("#leave_form").serialize(),
            mothod:"post",
            success:function (result) {
                if (result.status){
                    $("#leave_dialog").dialog("close");
                    $("#leave_table").datagrid("load");
                }else {
                    alert(result.message);
                }
            }
        })
    }
</script>

